<?php

namespace lxs\tools;

use Carbon\Carbon;
use lxs\config\BaseStatic;

class DataHandle extends BaseStatic
{

    /**
     * 获取今天的时间戳或者时间戳区间
     * @param string $parse 时间类型
     * @param string $type 时间戳类型
     * @return array
     */
    public static function getTimeRange(string $parse = 'today', string $type = 'timestamp'): array
    {

        if ($type == 'timestamp') {
            return match ($parse) {
                'today' => [Carbon::now()->startOfDay()->timestamp, Carbon::now()->endOfDay()->timestamp],
                'yesterday' => [Carbon::now()->yesterday()->startOfDay()->timestamp, Carbon::now()->yesterday()->endOfDay()->timestamp],
                'week' => [Carbon::now()->startOfWeek()->timestamp, Carbon::now()->endOfWeek()->timestamp],
                'month' => [Carbon::now()->startOfMonth()->timestamp, Carbon::now()->endOfMonth()->timestamp],
                'year' => [Carbon::now()->startOfYear()->timestamp, Carbon::now()->endOfYear()->timestamp],
                'last_week' => [Carbon::now()->previous()->startOfWeek()->timestamp, Carbon::now()->previous()->endOfWeek()->timestamp],
                'last_month' => [Carbon::now()->subMonth(1)->startOfMonth()->timestamp, Carbon::now()->subMonth(1)->endOfMonth()->timestamp],
                'last_year' => [Carbon::now()->subYear(1)->startOfYear()->timestamp, Carbon::now()->subYear(1)->endOfYear()->timestamp],
                default => [0, 0],
            };
        } else if ($type == 'date') {
            return match ($parse) {
                'today' => [Carbon::now()->startOfDay()->toDateTimeString(), Carbon::now()->endOfDay()->toDateTimeString()],
                'yesterday' => [Carbon::now()->yesterday()->startOfDay()->toDateTimeString(), Carbon::now()->yesterday()->endOfDay()->toDateTimeString()],
                'week' => [Carbon::now()->startOfWeek()->toDateTimeString(), Carbon::now()->endOfWeek()->toDateTimeString()],
                'month' => [Carbon::now()->startOfMonth()->toDateTimeString(), Carbon::now()->endOfMonth()->toDateTimeString()],
                'year' => [Carbon::now()->startOfYear()->toDateTimeString(), Carbon::now()->lastOfYear()->toDateTimeString()],
                'last_week' => [Carbon::now()->previous()->startOfWeek()->toDateTimeString(), Carbon::now()->previous()->endOfWeek()->toDateTimeString()],
                'last_month' => [Carbon::now()->subMonth(1)->startOfMonth()->toDateTimeString(), Carbon::now()->subMonth(1)->endOfMonth()->toDateTimeString()],
                'last_year' => [Carbon::now()->subYear(1)->startOfYear()->toDateTimeString(), Carbon::now()->subYear(1)->endOfYear()->toDateTimeString()],
                default => ['', ''],
            };
        }
    }


}
